package martian.t1me
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	
	import martian.t1me.core.Sequencable;
	import martian.t1me.core.Sequence;

	public class Shell extends EventDispatcher implements Sequencable
	{
		public var object:EventDispatcher;
		public var start:Function;
		public var stop:String;
		public var parameters:Array;
		
		public function Shell(object:EventDispatcher, start:Function, stop:String, parameters:Array = null)
		{
			this.object = object;
			this.start = start;
			this.stop = stop;
			this.parameters = parameters;
		}
		
		public function start():void
		{
			object.addEventListener(stop, close);
			start.apply(null, parameters);
		}
		
		private function close(e:*):void
		{
			object.removeEventListener(stop, close);
			dispatchEvent(new Event(Sequence.STOP));
		}
	}
}